package com.yyzw.activiti.modeler.controller;

import com.yyzw.activiti.modeler.model.ResponseVo;
import com.yyzw.activiti.modeler.service.EndTaskService;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("endTask")
public class EndTaskController {

    @Autowired
    EndTaskService endTaskService;

    @RequestMapping("dead")
    public ResponseVo modifyProcess(HttpServletRequest request){
        String taskId = request.getParameter("taskId");
        ActivityImpl endActivity =null;
        try {
            endActivity =endTaskService.findActivitiImpl(taskId,"end");
            endTaskService.commitProcess(taskId,null,endActivity.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseVo(false,"任务终止异常");
        }
        return new ResponseVo(true,"任务终止成功");
    }

}
